package com.zzyl.nursing.controller;

import java.util.List;

import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.domain.DeviceData;
import com.zzyl.nursing.dto.DeviceDataPageReqDto;
import com.zzyl.nursing.dto.DeviceDto;
import com.zzyl.nursing.service.IDeviceDataService;
import com.zzyl.nursing.vo.DeviceVo;
import com.zzyl.nursing.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.nursing.domain.Device;
import com.zzyl.nursing.service.IDeviceService;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 设备管理Controller
 * 
 * @author lww
 * @date 2024-11-18
 */
@RestController
@RequestMapping("/nursing/device")
@Api(tags = "设备管理相关接口")
@Slf4j
public class DeviceController extends BaseController {
    @Autowired
    private IDeviceService deviceService;

    @Autowired
    private IDeviceDataService deviceDataService;


        /**
         * 查询设备列表
         */
    @PreAuthorize("@ss.hasPermi('elder:device:list')")
    @GetMapping("/list")
    @ApiOperation("查询设备列表")
  public TableDataInfo<List<Device>> list(Device device) {
        startPage();
        List<Device> list = deviceService.selectDeviceList(device);
        return getDataTable(list);
    }



    @PostMapping("/syncProductList")
    @ApiOperation(value = "从物联网平台同步产品列表")
    public AjaxResult syncProductList(){
        deviceService.syncProductList();
        return AjaxResult.success();
     }

     @GetMapping("/allProduct") @ApiOperation("查询所有产品列表") public R<List<ProductVo>> allProduct(){
        return R.ok(deviceService.selectAllProduct());
    }

    @PostMapping("/register")
    @ApiOperation("注册设备")
    public AjaxResult register(@RequestBody DeviceDto deviceDto){
         deviceService.register(deviceDto);
        return AjaxResult.success();
     }

    @PostMapping("/queryDeviceDetail")
    @ApiOperation("查询设备详细数据")
    public R<DeviceVo> queryDeviceDetail(@RequestBody DeviceDto deviceDto){
        return R.ok(deviceService.queryDeviceDetail(deviceDto));
    }

//    @PostMapping("/queryThingModelPublished")
//    @ApiOperation("查看指定产品的已发布物模型中的功能定义详情")
//    public R queryThingModelPublished(@RequestBody DeviceDto deviceDto){
//        return R.ok(deviceService.queryThingModelPublished(deviceDto));
//    }

    /**
     * 1.6 查看指定产品的已发布物模型中的功能定义详情
     * @param deviceDto
     * @return
     */
    @PostMapping("/queryThingModelPublished")
    public R queryThingModelPublished(@RequestBody DeviceDto deviceDto){

        return R.ok(deviceService.queryThingModelPublished(deviceDto));
    }

    /**
     * 1.7 查询指定设备的物模型运行状态
     */
    @PostMapping("/queryDevicePropertyStatus")
    @ApiOperation("查询指定设备的物模型运行状态")
    public R queryDevicePropertyStatus(@RequestBody DeviceDto deviceDto){
        return R.ok(deviceService.queryDevicePropertyStatus(deviceDto));
    }




}


